package com.bac.rentmap.osm;

import com.bac.rentmap.model.Building;
import com.bac.rentmap.model.Street;

import javax.servlet.ServletContext;
import java.util.List;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

/**
 *
 * @author Ivan Holub
 */
public class StreetsReader {

    public List<Street> readStreets(ServletContext servletContext) {
        InputStream is = servletContext.getResourceAsStream("/WEB-INF/osm/highways.txt");
        List<Street> retValue = new ArrayList<Street>();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
            String line;
            while ((line = br.readLine()) != null) {
                Street h = new Street();
                String [] s = line.split("\t");
                h.setLat(s[0]);
                h.setLon(s[1]);
                h.setName(s[2]);
                retValue.add(h);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return retValue;
    }

}